package com.spring.springboot.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 项目名称: java_algorithm
 * @ClassName RabbitMqConfig
 * @Description
 * @Author huipanxing huipanxing@chinasofti.com   @Date 2022/6/8 18:38
 *
 * 1、简单模式-消息直接发送到队列 不需要交换机和路由等 可配置多个消费者进行抢占消费
 * 2、广播模式-消息发送交换机 由交换机发送给与它绑定的队列 不需要路由 可配置多个消费者进行重复消费
 * 3、路由模式-消息发送交换机 交换机通过路由键分发给队列 由消费者消费消息 为广播模式通过路由匹配规则  
 */
@Configuration
public class RabbitMqConfig {

    //简单模式
    @Bean
    public Queue simpleQueue(){
        return new Queue("simple-queue",true,false,false);
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("springboot-fanout");
    }


    //广播模式
    @Bean
    public Queue queue1(){
        return new Queue("springboot-queue1");
    }

    @Bean
    public Queue queue2(){
        return new Queue("springboot-queue2");
    }

    @Bean
    public Binding getBinding1(FanoutExchange fanoutExchange, Queue queue1){
        return BindingBuilder.bind(queue1).to(fanoutExchange);
    }

    @Bean
    public Binding getBinding2(FanoutExchange fanoutExchange, Queue queue2){
        return BindingBuilder.bind(queue2).to(fanoutExchange);
    }


    //路由模式
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("springboot-topic");
    }

    @Bean
    public Queue queue3(){
        return new Queue("springboot-queue3");
    }

    @Bean
    public Queue queue4(){
        return new Queue("springboot-queue4");
    }

    @Bean
    public Binding getBinding3(TopicExchange topicExchange,Queue queue3){
        return BindingBuilder.bind(queue3).to(topicExchange).with("xiao.*");
    }
    @Bean
    public Binding getBinding4(TopicExchange topicExchange,Queue queue4){
        return BindingBuilder.bind(queue4).to(topicExchange).with("xiao.*");
    }
}
